﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using AussieAuto.Controller;

namespace AussieAuto.WPF.Interface
{
    /// <summary>
    /// Interaction logic for RibbonWindow1.xaml
    /// </summary>
    public partial class RibbonWindow1 : RibbonWindow
    {
        public RibbonWindow1()
        {
            InitializeComponent();

            // Insert code required on object creation below this point.
        }
              

        


        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            groupBoxValidation.Visibility = System.Windows.Visibility.Hidden;
            customerControl1.customerChanged += new EventHandler(customer_changed);
            carControl1.carChanged += new EventHandler(car_changed);
            repairControl1.repairJobChanged += new EventHandler(repairJob_changed);
            carControl1.validationCompleted += new EventHandler(validationCompleted);
            customerControl1.validationCompleted += new EventHandler(validationCompleted);//
            repairControl1.validationCompleted += new EventHandler(validationCompleted);
            payment1.validationCompleted += new EventHandler(validationCompleted);

            tabCustomer.IsSelected = true;
            todayJobs1.Visibility = System.Windows.Visibility.Hidden;// = false;
            tabContainer.Visibility = System.Windows.Visibility.Visible;
            reportsControl1.Visibility = System.Windows.Visibility.Hidden;



            AussieAuto.DataAccess.AussieAutoEntityModel entityContext = new DataAccess.AussieAutoEntityModel();
            customerControl1.controller = new CustomerCarController(entityContext);
            carControl1.controller = new CustomerCarController(entityContext);
            repairControl1.controller = new RepairJobController(entityContext);
            invoiceControl1.controller = new InvoicePaymentController(entityContext);
            payment1.controller = new InvoicePaymentController(entityContext);
            quoteControl1.controller = new QuoteController(entityContext);
            todayJobs1.entityContext = entityContext;

        
        }



        private void validationCompleted(object sender, EventArgs e)
        {
            var errorList = sender as List<string>;

            if (errorList.Count > 0)
            {
                groupBoxValidation.Visibility = System.Windows.Visibility.Visible;
                validationListBox.ItemsSource = errorList;
            }
            else
            {
                groupBoxValidation.Visibility = System.Windows.Visibility.Hidden;
            }
        
        }

        private void bnAddSave_Click(object sender, RoutedEventArgs e)
        {
           
        }


        void customer_changed(object sender, EventArgs e)
        {
            if (customerControl1.selectedCustomer != null )
            {

             //   validationCompleted(new List<string>(), new EventArgs());
                tabCars.Header = customerControl1.selectedCustomer.FirstName.Trim() + "'s Cars";
                carControl1.Customer = customerControl1.selectedCustomer;
            }

        }


        void car_changed(object sender, EventArgs e)
        {
            if (carControl1.SelectedCar != null)
            {
                tabRepairJob.Header = carControl1.SelectedCar.RegoNumber + " Repair Jobs";
                repairControl1.own = carControl1.own;
                quoteControl1.own = carControl1.own;
            }
        }

        void repairJob_changed(object sender, EventArgs e)
        {
            if (repairControl1.SelectedRepairJob != null)
            {
                invoiceControl1.RepairJob = repairControl1.SelectedRepairJob;
                payment1.RepairJob = repairControl1.SelectedRepairJob;
             
            }
        }

        private void carControl1_Loaded(object sender, RoutedEventArgs e)
        {
   
           
        }

        private void repairControl1_Loaded(object sender, RoutedEventArgs e)
        {
         
        }

        private void tabContainer_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void customerImage_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }

        private void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }


        private void btnCustomer_Click_1(object sender, RoutedEventArgs e)
        {
 tabCustomer.IsSelected = true;
 customerControl1.firstNameTextBox.Focus();
 todayJobs1.Visibility = System.Windows.Visibility.Hidden;// = false;
 tabContainer.Visibility = System.Windows.Visibility.Visible;
 reportsControl1.Visibility = System.Windows.Visibility.Hidden;

        }

        private void btnCalander_Click(object sender, RoutedEventArgs e)
        {
            todayJobs1.Visibility = System.Windows.Visibility.Visible;// = false;
            tabContainer.Visibility = System.Windows.Visibility.Hidden;
            reportsControl1.Visibility = System.Windows.Visibility.Hidden;
        }

        private void todayJobs1_Loaded(object sender, RoutedEventArgs e)
        {
            //todayJobs1.Visibility = System.Windows.Visibility.Hidden;// = false;
            //tabContainer.Visibility = System.Windows.Visibility.Hidden;
            //reportsControl1.Visibility = System.Windows.Visibility.Hidden;
        }

        private void btnReports_Click(object sender, RoutedEventArgs e)
        {
            todayJobs1.Visibility = System.Windows.Visibility.Hidden;// = false;
            tabContainer.Visibility = System.Windows.Visibility.Hidden;
            reportsControl1.Visibility = System.Windows.Visibility.Visible;
        }

        private void customerControl1_Loaded(object sender, RoutedEventArgs e)
        {

        }

   

    }
}
